<?php
declare (strict_types = 1);

namespace app\api\controller\v1;

use app\api\model\v1\GatherFile;
use app\BaseController;
use think\Request;

class Gather extends BaseController
{


    /**
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * 2021/12/9
     * lhl
     * 采集列表
     */
    public function getGatherList(){
        $limit = $this->request->param('limit',10);
        $map = [];
        if ($this->request->has('project_id') && !empty($this->request->param('project_id'))) {
            $map[] = ['project_id', '=', $this->request->param('project_id')];
        }
        if ($this->request->has('user_id') && !empty($this->request->param('user_id'))) {
            $map[] = ['user_id', '=', $this->request->param('user_id')];
        }
        if ($this->request->has('project_type_id') && !empty($this->request->param('project_type_id'))) {
            $map[] = ['project_type_id', '=', $this->request->param('project_type_id')];
        }
        if ($this->request->has('project_sample_id') && !empty($this->request->param('project_sample_id'))) {
            $map[] = ['project_sample_id', '=', $this->request->param('project_sample_id')];
        }
        //只显示未分配指标的
        $map[] = array('is_allot','=',GatherFile::IS_ALLOT_ZERO);
        $res = GatherFile::with(['user','project','projectType','projectSample','folder'])->where($map)->order('id desc')->paginate($limit)->each(function ($item,$key){
            $item['show'] = '';
            $item['loading'] = true;
            return $item;
        });
        return $this->response($res);
    }
}
